package org.ftc.service;

import java.util.Date;
import java.util.List;

import org.ftc.dao.RoleAuthDao;
import org.ftc.domain.RoleAuth;
import org.ftc.form.RoleAuthForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;


@Service
public class RoleAuthService {
 
	@Autowired
	RoleAuthDao roleAuthDao;
	
	public RoleAuth load(String id) {
		return roleAuthDao.load(id);
	}

	public RoleAuth get(String id) {
		return roleAuthDao.get(id);
	}

	public synchronized boolean save(RoleAuth entity) {
		entity.setCreationUser(SecurityContextHolder.getContext().getAuthentication().getName());
		entity.setCreationDate(new Date());
		return roleAuthDao.save(entity);
	}

	public synchronized boolean saveOrUpdate(RoleAuth entity) {
		return roleAuthDao.saveOrUpdate(entity);
	}

	public synchronized boolean update(RoleAuth entity) {
		entity.setModifyDate(new Date());
		entity.setModifyUser(SecurityContextHolder.getContext().getAuthentication().getName());
		return roleAuthDao.update(entity);
	}

	public synchronized boolean delete(RoleAuth entity) {
		return roleAuthDao.delete(entity);
	}

	public synchronized boolean delete(String id) {
		return roleAuthDao.delete(id);
	}

	public List<RoleAuth> findPage(int offset, int pageSize) {
		return roleAuthDao.findPage(offset, pageSize);
	}

	public List<RoleAuth> findAll() {
		return roleAuthDao.findAll();
	}

	public long countAll() {
		return roleAuthDao.countAll();
	}
	
	public List<RoleAuth> findPage(RoleAuthForm form ,int offset, int pageSize) {
		return roleAuthDao.findPage(form, offset, pageSize);
	}

	public long count(RoleAuthForm form) {
		return roleAuthDao.count(form);
	}
	
	public RoleAuth getByAuthName(String name){
		return roleAuthDao.getByAuthName(name);
	}
	
}
